<%-- 
    Document   : mantevisitador
    Created on : 08/15/2013, 10:23:34 PM
    Author     : grakeskull
--%>

<%@page import="edu.capex.farmacus.encapsulates.Autenticacion"%>
<%@page import="edu.capex.farmacus.Manager.SupervisoresManager"%>
<%@page import="edu.capex.farmacus.encapsulates.Supervisores"%>
<%@page import="edu.capex.farmacus.encapsulates.Visitadores"%>
<%@page import="edu.capex.farmacus.Manager.VisitadoresManager"%>
<%@page contentType="text/html" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>

<%
    Visitadores visitadorAMod = ((Autenticacion) request.getSession().getAttribute("usuarioLogeado")).getIdVisitador();

    if (request.getParameter("nombre") != null && request.getParameter("cedula") != null
            && request.getParameter("telefono") != null && request.getParameter("supervisor") != null && request.getParameter("correo") != null
            && request.getParameter("id") != null && request.getParameter("moid") == null) {

        //Visitadores visitador = new Visitadores(new Integer(request.getParameter("id")));
        Visitadores visitador = new VisitadoresManager().findVisitadores(new Integer(request.getParameter("id")));
        boolean existe = false;

        if (visitador == null) {
            visitador = new Visitadores();
        } else {
            existe = true;
        }

        visitador.setId(new Integer(request.getParameter("id")));
        visitador.setCedula(request.getParameter("cedula"));
        visitador.setCorreovisitador(request.getParameter("correo"));
        visitador.setTelefono(request.getParameter("telefono"));
        visitador.setNombre(request.getParameter("nombre"));
        visitador.setSupervisor(new Integer(request.getParameter("supervisor")));

        if (existe) {
            new VisitadoresManager().edit(visitador);
        } else {
        }

    }

%>
<html>
    <head>
        <%@include file="/resources/header.jsp" %>
        <script src="../js/bsa.js"></script>
    </head>
    <%@include file="/resources/header1.jsp" %>
    <body class="preview" data-spy="scroll" data-target=".subnav" data-offset="80">

        <div class="container">
           
            <section id="typography">
               

                <%@include file="/admin/visitadores/menuvisitador.jsp" %>

                <h2>Mantenimiento Visitador </h2>

                <section id="forms">

                    <form class="form-horizontal well" method="POST" id="myForm">
                        <fieldset>

                            <%if (visitadorAMod != null) {%>

                            <input type="hidden" name="id" value="<%=visitadorAMod.getId()%>"/>
                            <div class="control-group">
                                <label class="control-label" for="input01">Nombre</label>
                                <div class="controls">
                                    <input type="text" class="input-xlarge" data-required id="input01" name="nombre" readonly value="<%=visitadorAMod.getNombre()%>"/>
                                </div>
                            </div>

                            <div class="control-group">
                                <label class="control-label" for="input01">cedula</label>
                                <div class="controls">
                                    <input type="text" class="input-xlarge" data-required id="input01" name="cedula" value="<%=visitadorAMod.getCedula()%>"/>
                                </div>  
                            </div>

                            <div class="control-group">
                                <label class="control-label" for="input01">Telefono</label>
                                <div class="controls">
                                    <input type="text" class="input-xlarge" data-required id="input01" name="telefono" value="<%=visitadorAMod.getTelefono()%>"/>
                                </div>
                            </div>

                            <div class="control-group">
                                <label class="control-label" for="input01">Supervisor</label>
                                <div class="controls">
                                    <select name="supervisor" class="input-xlarge">
                                        <%
                                            for (Supervisores temp : new SupervisoresManager().findSupervisoresEntities()) {
                                                if (visitadorAMod.getSupervisor() == temp.getIdsupervisores()) {
                                        %>
                                        <option value="<%=temp.getIdsupervisores()%>" selected><%=temp.getNombresupervisores()%></option>
                                        <%} else {%>
                                        <%}%>
                                        <%}%>
                                    </select>
                                </div>
                            </div>

                            <div class="control-group">
                                <label class="control-label" for="input01">Correo</label>
                                <div class="controls">
                                    <input type="text" class="input-xlarge" data-required id="input01" name="correo" value="<%=visitadorAMod.getCorreovisitador()%>"/>
                                </div>
                            </div>



                            <div class="form-actions">
                                <button type="submit" class="btn btn-primary" name="modificar">Modificar</button>
                                <button type="reset" class="btn">Cancelar</button>
                            </div>
                            <%} else {%>
                            <input type="hidden" name="id" value="<%=new VisitadoresManager().nextId()%>"/>
                            <div class="control-group">
                                <label class="control-label" for="input01">Nombre</label>
                                <div class="controls">
                                    <input type="text" class="input-xlarge" data-required id="input01" name="nombre">
                                </div>
                            </div>

                            <div class="control-group">
                                <label class="control-label" for="input01">cedula</label>
                                <div class="controls">
                                    <input type="text" class="input-xlarge" data-required id="input01" name="cedula">
                                </div>
                            </div>

                            <div class="control-group">
                                <label class="control-label" for="input01">Telefono</label>
                                <div class="controls">
                                    <input type="text" class="input-xlarge" data-required id="input01" name="telefono">
                                </div>
                            </div>

                            <div class="control-group">
                                <label class="control-label" for="input01">Supervisor</label>   
                                <div class="controls">
                                    <select name="supervisor" class="input-xlarge">
                                        <%
                                            for (Supervisores temp : new SupervisoresManager().findSupervisoresEntities()) {
                                        %>
                                        <option value="<%=temp.getIdsupervisores()%>"><%=temp.getNombresupervisores()%></option>
                                        <%}%>
                                    </select>
                                </div>
                            </div>

                            <div class="control-group">
                                <label class="control-label" for="input01">Correo</label>
                                <div class="controls">
                                    <input type="text" class="input-xlarge" data-required id="input01" name="correo">
                                </div>
                            </div>


                            <div class="form-actions">
                                <button type="submit" class="btn btn-primary" name="guardar">Agregar</button>
                                <button type="reset" class="btn">Cancelar</button>
                            </div>
                            <%}%>
                        </fieldset>
                    </form>

                    <%@include file="/resources/footer1.jsp" %>
                </section>
            </section>
        </div>
        <script type="text/javascript">
            $(document).ready(function() {
                $("#myTable").tableFilter();
                $('#myForm').validate({
                    onKeyup: true,
                    eachValidField: function() {

                        $(this).closest('div').removeClass('error').addClass('success');
                    },
                    eachInvalidField: function() {

                        $(this).closest('div').removeClass('success').addClass('error');
                    }
                });

            });
        </script>
    </body>
</html>

